using System;
using Server;
using Server.Mobiles;
using Server.Items;
using System.Collections.Generic;

namespace Server.Engines.Quests.RandomQuests
{
	public class QuestAcceptConversation : QuestConversation
	{
		public override object Message
		{
			get 
			{
				return "Good luck and take care of yourself.";
			}
		}

		public QuestAcceptConversation()
		{
		}
	}

    public class RandomQuestKillObjective : QuestObjective
	{
		private RandomMonster m_Objective;

		public override object Message
		{
			get
			{
				return @"Slay a " + m_Objective.Name;
			}
		}

		public override int MaxProgress { get { return m_Objective.Count; } }

		public override void RenderProgress( BaseQuestGump gump )
		{
			if ( !Completed )
			{
				gump.AddLabel( 70, 260, 0x64, m_Objective.Name);
				gump.AddLabel( 70, 280, 0x64, CurProgress.ToString() );
				gump.AddLabel( 100, 280, 0x64, "/" );
				gump.AddLabel( 130, 280, 0x64, MaxProgress.ToString() );
			}
			else
			{
				base.RenderProgress( gump );
			}
		}

		public override void OnKill( BaseCreature creature, Container corpse )
		{
            foreach(Type type in m_Objective.Types)
                if (type.IsInstanceOfType(creature))
                {
                    CurProgress++;
                    break;
                }
		}

		public override void OnComplete()
		{
			((RandomQuest)System).CheckComplete();
			System.From.PlaySound( 0x431 );
			System.ShowQuestLogUpdated();
		}

		public RandomQuestKillObjective()
		{
		}

        public RandomQuestKillObjective(RandomMonster monster)
		{
			m_Objective = monster;
		}

		public override void ChildDeserialize( GenericReader reader )
		{
			base.ChildDeserialize( reader );

			int version = reader.ReadInt();

            m_Objective = RandomMonster.Deserialize(reader);
		}
		public override void ChildSerialize( GenericWriter writer )
		{
			base.ChildSerialize( writer );

			writer.Write( (int)1 ); // version

			m_Objective.Serialize( writer );
		}
	}

    public class RandomQuestFindObjective : QuestObjective
    {

        private RandomMonster m_Objective;

        public override object Message
        {
            get
            {
                return @"Seek " + m_Objective.Name;
            }
        }

        public override int MaxProgress { get { return m_Objective.Count; } }

        public override void RenderProgress(BaseQuestGump gump)
        {
            if (!Completed)
            {
                gump.AddLabel(70, 260, 0x64, m_Objective.Name);
                gump.AddLabel(70, 280, 0x64, CurProgress.ToString());
                gump.AddLabel(100, 280, 0x64, "/");
                gump.AddLabel(130, 280, 0x64, MaxProgress.ToString());
            }
            else
            {
                base.RenderProgress(gump);
            }
        }

        public override void OnKill(BaseCreature creature, Container corpse)
        {
            foreach (Type type in m_Objective.Types)
                if (type.IsInstanceOfType(creature))
                {
                    CurProgress++;
                    break;
                }
        }

        public override void OnComplete()
        {
            ((RandomQuest)System).CheckComplete();
            System.From.PlaySound(0x431);
            System.ShowQuestLogUpdated();
        }

        public RandomQuestFindObjective()
        {
        }

        public RandomQuestFindObjective(RandomMonster monster)
        {
            m_Objective = monster;
        }

        public override void ChildDeserialize(GenericReader reader)
        {
            base.ChildDeserialize(reader);

            int version = reader.ReadInt();

            m_Objective = RandomMonster.Deserialize(reader);
        }
        public override void ChildSerialize(GenericWriter writer)
        {
            base.ChildSerialize(writer);

            writer.Write((int)1); // version

            m_Objective.Serialize(writer);
        }
    }

	public class ReturnToQuestgiverObjective : QuestObjective
	{
		public override object Message
		{
			get
			{
				return @"Return to your local talkmaster";
			}
		}

        public ReturnToQuestgiverObjective()
		{
		}

		public override void OnComplete()
		{
            if (Utility.RandomMinMax(1, 4) == 1)
            {
                System.From.AddToBackpack(new Gold(((RandomQuest)System).Level * Utility.RandomMinMax(250, 400)));
            }
            else
            {
                System.From.AddToBackpack(new Gold(((RandomQuest)System).Level * Utility.RandomMinMax(150, 250)));
            }
            System.AddConversation(new QuestgiverThanksConversation());
			System.From.PlaySound( 0x431 );
			System.Complete();
		}
	}

	public class QuestgiverThanksConversation : QuestConversation
	{
		public override object Message
		{
			get
			{
				return "Thanks for your endeavour. Here's your reward.";
			}
		}

        public QuestgiverThanksConversation()
		{
		}
	}

}